#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>

#define flr(x,l,r) for (int x = l; x <= r; ++ x)
#define frl(x,r,l) for (int x = r; x >= l; -- x)
#define LL long long 
#define mt memset 
#define szf sizeof
#define INF 0x3f3f3f3f
#define in(x) scanf("%d", &x)
#define out(x) printf("%d", x)
#define inll(x) scanf("%lld", &x)
#define outll(x) printf("%lld", x)
#define pn printf("\n")
#define con continue
#define bk break
#define vc vector 
#define pb push_back
#define sz size
#define PII pair<int, int>
#define x first
#define y second

using namespace std;

const int N = 1010, M = 20010;

int n, m, k;
int dist[N];
int e[M], w[M], ne[M], h[N], idx;
deque<int> q;
bool st[N];

void add(int a, int b, int c) {
    e[idx] = b, w[idx] = c, ne[idx] = h[a], h[a] = idx ++ ;
}

bool check(int bound) {
    mt(dist, 0x3f, szf dist);
    dist[1] = 0;
    
    q.push_back(1);
    
    mt(st, 0, szf st);
    while (q.sz()) {
        int t = q.front();
        q.pop_front();
        
        if (st[t]) con;
        st[t] = true;
        
        for (int i = h[t]; ~i; i = ne[i]) {
            int j = e[i], x = w[i] > bound;
            if (dist[j] > dist[t] + x) {
                dist[j] = dist[t] + x;
                if (x) q.push_back(j);
                else q.push_front(j);
            }
        }
    }
    
    return dist[n] <= k;
}

int main() {
	cin >> n >> m >> k;
	
	mt(h, -1, szf h);
	while (m -- ) {
	    int a, b, c;
	    in(a), in(b), in(c);
	    add(a, b, c), add(b, a, c);
	}
	
	int l = 0, r = 1e6 + 1;
	while (l < r) {
	    int mid = l + r >> 1;
	    if (check(mid)) r = mid;
	    else l = mid + 1;
	}
	
	if (r == 1e6 + 1) puts("-1");
	else out(r), pn;
	
	return 0;
}